<!--
  - Copyright (c) 2018.
  - 北京九思金信科技有限公司对该文件内容保留所有权利。
  - 未经许可，不得私自拷贝、传播、发布、引用该文件内容，违者将被追究法律责任。
  -->

<template>
  <div>
    <customer-list v-if="status=='cust-list'" :propsBind="propsBind" @returnValue="returnValue"/>
    <customer-corp-add v-if="status=='corp-add'" :propsBind="propsBind" @returnValue="returnValue"/>
    <customer-corp v-if="status=='corp'" :propsBind="propsBind" @returnValue="returnValue" :customerId="customerId" :initEdit = "initEdit"/>
    <customer-person-add v-if="status=='person-add'" :propsBind="propsBind" @returnValue="returnValue"/>
    <customer-person v-if="status=='person'" :propsBind="propsBind" @returnValue="returnValue" :customerId="customerId" :initEdit = "initEdit"/>
    <fengbao v-if="status=='fengbao'" :propsBind="propsBind" @returnValue="returnValue"/>
  </div>
</template>

<script>
import CustomerList from './CustomerList'
import CustomerCorp from './corp/CustomerCorp'
import CustomerCorpAdd from './corp/CustomerCorpAdd'
import CustomerPersonAdd from './person/CustomerPersonAdd'
import CustomerPerson from './person/CustomerPerson'
import Fengbao from './fengbao/Fengbao'

  export default {
    name: "CustomerMain",
    components: {
      Fengbao,
      CustomerList,CustomerCorpAdd,  CustomerPersonAdd, CustomerPerson,CustomerCorp},
    props: ['id', 'customerType'],
    data() {
      return {
        propsBind: {
          //展示页面
          currentPage: 1,
          //页面条数
          pageSize: 8
        },
        status: 'cust-list',
        customerId: null,
        initEdit : false,
      }
    },
    mounted(){
      this.load()
    },
    watch:{
      id: {
        handler(val) {
          this.load()
        },
        immediate: true
      },
      customerType: {
        handler(val) {
          this.load()
        },
        immediate: true
      }
    },
    methods: {
      returnValue(value) {
        this.propsBind = value.propsBind
        this.status = value.switchShow
        this.customerId = value.customerId
        this. initEdit =  value.initEdit
      },
      load(){
        if(this.id && this.customerType
          && this.id != '' && this.customerType != ''){
          if(this.customerType == 'ENTERPRISE'){
            this.customerId = this.id
            this.status = 'corp'
            this.initEdit =  true
          }
          if(this.customerType == 'PERSONAL'){
            this.customerId = this.id
            this.status = 'person'
            this.initEdit =  true
          }
        }else{
          this.status = 'cust-list'
        }
      }
    }
  }



</script>

<style scoped>

</style>
